<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>经销总账号管理页面</title>
    <link rel="stylesheet" href="css/stockplan.css">
    <link rel="stylesheet" href="./css/bootstrap.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/purchase_order.js"></script>

    <style>
        #main {
            background-image: url(./img/002.png);
        }

        .black_overlay {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.8;
            opacity: .80;
            filter: alpha(opacity=88);
        }

        .white_content {
            display: none;
            position: absolute;
            top: 25%;
            left: 25%;
            width: 55%;
            height: 55%;
            padding: 20px;
            border: 10px solid orange;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }
    </style>
</head>
<body id="main">
<div id="lwp">
    此处是经销总账号管理页面
    <button type="button" id="createDealer" onclick="openDialog()">新增</button>
    <button type="button" id="updateDealer" onclick="openDialog2()">修改</button>
    <button type="button" id="rePassword" onclick="rePassword()">重置密码</button>
    <button type="button" id="deleteDealer" onclick="deleteDealer()">删除</button>
    <button type="button" id="relationDealer" onclick="openDialog3()">关联</button>
    <button type="button" id="queryBoss" @click="getData()">查询</button>

    <input id="username3" placeholder="用户名">
    <input id="dealerName3" placeholder="经销商名称">
    <input id="status" placeholder="状态">

    <div id="up" class="white_content">//修改
        <input id="username2" placeholder="用户名" onclick="focus()">
        <input id="dealerName2" placeholder="经销商名称">
        <input id="contact2" placeholder="联系人">
        <input id="phone2" placeholder="手机号码">
        <input id="email2" placeholder="电子邮箱">
        <input id="remark2" placeholder="备注">
        <a href="javascript:void(0)" onclick="updateDealer()">确认</a>
        <a href="javascript:void(0)" onclick="closeDialog2()">返回</a>
    </div>

    <div id="light" class="white_content">//新增
        <p id="demo">请输入用户名</p>
        <input id="username" placeholder="用户名" autofocus="autofocus" onblur="isName">
        <input id="dealerName" placeholder="经销商名称" onblur="isName">
        <input id="contact" placeholder="联系人">
        <input id="phone" placeholder="手机号码">
        <input id="email" placeholder="电子邮箱">
        <input id="remark" placeholder="备注">
        <a href="javascript:void(0)" onclick="createDealer()">确认</a>
        <a href="javascript:void(0)" onclick="closeDialog()">返回</a>
    </div>


    <div id="con" class="white_content">//关联
        <input id="Community" placeholder="机构名称">
        <input id="Pickname" placeholder="经销商简称">
        <input id="Area" placeholder="区域">
        <input id="SendMoney" placeholder="实际发货余额">
        <input id="CountMoney" placeholder="实际商折余额">
        <input id="PaidMoney" placeholder="已缴纳保证金">
        <a href="javascript:void(0)" onclick="relationDealer()">确认</a>
        <a href="javascript:void(0)" onclick="closeDialog3()">返回</a>
    </div>
    <div id="fade" class="black_overlay"></div>


    <div id="showtable">
        <table id="table1">
            <thead>
            <tr>
                <th><input type="checkbox"></th>
                <th>序号</th>
                <th>用户名</th>
                <th>经销商名</th>
                <th>电话号码</th>
                <th>联系人</th>
                <th>电子邮箱</th>
                <th>账号创建人</th>
                <th>创建时间</th>
                <th>备注</th>
                <th>修改时间</th>
                <th>修改人</th>
                <th>状态</th>


            </tr>

            </thead>
            <tbody>
            <tr v-for="(it,index) in dealer_list">
				<td><input type="checkbox"></td>
                <td>{{it.id}}</td>
				<td>{{it.username}}</td>
                <td>{{it.dealerName}}</td>
                <td>{{it.phone}}</td>
                <td>{{it.contact}}</td>
                <td>{{it.email}}</td>
                <td>{{it.createPeople}}</td>
                <td>{{it.createTime}}</td>
                <td>{{it.remark}}</td>
                <td>{{it.updateTime}}</td>
                <td>{{it.updatePeople}}</td>
                <td>{{it.status}}</td>

            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
<script>
    var requestURL = 'http://127.0.0.1:9000/';

    function createDealer() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/createDealer", //请求地址
                type: 'post', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    username: $("#username").val(),
                    dealerName: $("#dealerName").val(),
                    contact: $("#contact").val(),
                    phone: $("#phone").val(),
                    email: $("#email").val(),
                    remark: $("#remark").val()
                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }


    function updateDealer() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/updateDealer", //请求地址
                type: 'get', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    id: "13",
                    username: $("#username2").val(),
                    dealerName: $("#dealerName2").val(),
                    contact: $("#contact2").val(),
                    phone: $("#phone2").val(),
                    email: $("#email2").val(),
                    remark: $("#remark2").val()
                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }

    function rePassword() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/rePassword", //请求地址
                type: 'get', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    username: "zxf",
                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }

    function relationDealer() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/relationDealer", //请求地址
                type: 'get', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    id: "13",
                    Community: $("#Community").val(),
                    Pickname: $("#Pickname").val(),
                    Area: $("#Area").val(),
                    SendMoney: $("#SendMoney").val(),
                    CountMoney: $("#CountMoney").val(),
                    PaidMoney: $("#PaidMoney").val()
                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }


    function isName() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/isName", //请求地址
                type: 'get', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    username: $("#username").val()

                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }

    function deleteDealer() {
        $(document).ready(function () {

            $.ajax({
                url: requestURL + "/dealer/deleteDealer", //请求地址
                type: 'get', //请求方式
                dataType: 'json', //返回的数据格式
                data: {
                    id: "12"

                },
                success: (function (res) {

                    if (res['code'] == 0) {
                        alert(res.message)


                    } else {
                        alert(res.message)
                    }
                })
            })
        })
    }

    // function queryBoss(){
    // 	$(document).ready(function () {
    //
    // 		$.ajax({
    // 			url: requestURL + "/dealer/queryBoss", //请求地址
    // 			type: 'get', //请求方式
    // 			dataType: 'json', //返回的数据格式
    // 			data: {
    // 				username: $("#username3").val(),
    // 				dealerName: $("#dealerName3").val(),
    // 				status:$("status").val()
    //
    // 			},
    // 			success:(function (res) {
    // 				for(var i=0;i<res.data.length;i++){
    // 					(res.data[i]);
    //
    // 				}
    //
    //
    // 			})
    // 		})
    // 	})
    // }


    $(function () {
    })

    function openDialog() {
        document.getElementById('light').style.display = 'block';
        document.getElementById('fade').style.display = 'block'
    }

    function openDialog2() {
        document.getElementById('up').style.display = 'block';
        document.getElementById('fade').style.display = 'block'
    }

    function closeDialog() {
        document.getElementById('light').style.display = 'none';
        document.getElementById('fade').style.display = 'none'
    }

    function closeDialog2() {
        document.getElementById('up').style.display = 'none';
        document.getElementById('fade').style.display = 'none'
    }

    function openDialog3() {
        document.getElementById('con').style.display = 'block';
        document.getElementById('fade').style.display = 'block'
    }

    function closeDialog3() {
        document.getElementById('con').style.display = 'none';
        document.getElementById('fade').style.display = 'none'
    }


    var host = "http://127.0.0.1:9000";
    //var host="http://8.140.39.72:9000";
    var app = new Vue({
        el: "#lwp",

        data: {
            dealer_list: [ {
				"id": 3,
				"dealerCode": null,
				"username": "jxs123456",
				"dealerName": "测试经销商",
				"pickname": null,
				"community": null,
				"password": null,
				"area": null,
				"phone": "11256482658",
				"contact": "经销商1",
				"email": "jxs@qq.com",
				"idcard": null,
				"createPeople": "zxf",
				"createTime": "2021-10-11",
				"remark": "测试",
				"status": 1,
				"leaderCode": null,
				"dealerTip": null,
				"credits": null,
				"sendMoney": null,
				"countMoney": null,
				"paidMoney": null,
				"integral": null,
				"updateTime": "2021-10-11",
				"updatePeople": null
			}]

        },
        methods: {
            getData: function () {
                $.ajax({
                    url: host + "/dealer/queryBoss",
                    data: {
                        username: $("#username3").val(),
                        dealerName: $("#dealerName3").val(),
                        status: $("status").val()
                    },
                    datatype: "JSON",
                    method: "GET",
                    success: function (re) {
                        if (re != null) {
                            app.dealer_list = [];
                            for (var i = 0; i < re.data.length; i++) {
                                app.dealer_list.push(re.data[i]);
                            }

                        } else {
                            alert("服务器正忙...");
                            console.log(re)
                        }
                    }
                })
            },
            //上一页的方法
            prePage: function () {
                if (app.page > 1) {
                    app.page = app.page - 1;
                    this.getData();
                }
            },
            //下一页的方法
            nextPage: function () {
                if (app.page <= app.total / app.rows) {
                    app.page = app.page + 1;
                    this.getData();
                }
            },
        },
        created: function () {
            this.getData()
        }
    });
</script>
</html>
